ec8b2cf7b763a8bdd04433fd9db3674f78369be3,src/main/java/io/mewbase/server/impl/ConnectionImpl.java,ConnectionImpl,handleSubClose,#BsonObject#,210
Before Change
@Override
public void handleSubClose(BsonObject frame) {
checkContext();
if (!isAuthorized(Protocol.SUBCLOSE_FRAME)) {
return;
}
Integer subID = frame.getInteger(Protocol.SUBCLOSE_SUBID);
if (subID == null) {
missingField(Protocol.SUBCLOSE_SUBID, Protocol.SUBCLOSE_FRAME);
return;
}
Integer requestID = frame.getInteger(Protocol.REQUEST_REQUEST_ID);
if (requestID == null) {
missingField(Protocol.REQUEST_REQUEST_ID, Protocol.SUBCLOSE_FRAME);
return;
}
SubscriptionImpl subscription = subscriptionMap.remove(subID);
if (subscription == null) {
invalidField(Protocol.SUBCLOSE_SUBID, Protocol.SUBCLOSE_FRAME);
return;
}
subscription.close();
BsonObject resp = new BsonObject();
resp.put(Protocol.RESPONSE_OK, true);
After Change
public void handleSubClose(BsonObject frame) {
checkContext();
CompletableFuture<Boolean> authorisedCF = user.isAuthorised(Protocol.SUBCLOSE_FRAME);
Consumer<BsonObject> frameConsumer = (protocolFrame) -> {
Integer subID = protocolFrame.getInteger(Protocol.SUBCLOSE_SUBID);
if (subID == null) {
missingField(Protocol.SUBCLOSE_SUBID, Protocol.SUBCLOSE_FRAME);
return;
}
Integer requestID = protocolFrame.getInteger(Protocol.REQUEST_REQUEST_ID);
if (requestID == null) {
missingField(Protocol.REQUEST_REQUEST_ID, Protocol.SUBCLOSE_FRAME);
return;
}
SubscriptionImpl subscription = subscriptionMap.remove(subID);
if (subscription == null) {
invalidField(Protocol.SUBCLOSE_SUBID, Protocol.SUBCLOSE_FRAME);
return;
}
subscription.close();
BsonObject resp = new BsonObject();
resp.put(Protocol.RESPONSE_OK, true);
resp.put(Protocol.RESPONSE_REQUEST_ID, requestID);
writeResponse(Protocol.RESPONSE_FRAME, resp);
};
authorisedCF.handle((res, ex) -> {
handleFrame(frame, frameConsumer, res, ex);
return null;
});
}
@Override